<template>
	<!-- 电梯信息管理/资源管理 -->
	<div class="operationBox heightMax publicbox planBox" v-loading='loading'>
		<el-row :gutter="10">
			<el-col :span="5">
				<div class="colItem">
					<span class="font14 searchCode">资源名称：</span>
					<el-input size="mini" @keyup.enter.native="find" placeholder="请输入资源名称" clearable v-model="query"></el-input>
				</div>
			</el-col>
			<el-col :span="5">
				<div class="colItem">
					<span class="font14 searchCode">资源类型：</span>
					<el-select v-model="resource" placeholder="请选择资源类型" size="mini" clearable>
						<el-option v-for="item in resourceArr" :label="item.label" :value="item.value" :key='item.value'></el-option>
					</el-select>
				</div>
			</el-col>
			<el-col :span="1.5">
				<div v-if="showVis">
					<el-popover placement="bottom" width="400" v-model="showProp" trigger="manual">
						<el-row :gutter="10" class='currentRow1'>
							<el-col :offset='1' :span="11">
								<el-row>
									<el-col :span="8">
										<span class="font14 marginTop5">播放模式：</span>
									</el-col>
									<el-col :span="16">
										<el-select size="mini" placeholder="请选择播放模式" clearable v-model="playMode">
											<el-option v-for="item in playModeArr" :value="item.value" :key="item.value" :label="item.label"></el-option>
										</el-select>
									</el-col>
								</el-row>
							</el-col>
							<el-col :offset='1' :span="11">
								<el-row>
									<el-col :span="8">
										<span class="font14 marginTop5">适用终端：</span>
									</el-col>
									<el-col :span="16">
										<el-select size="mini" placeholder="请选择适用终端" clearable v-model="terminal">
											<el-option v-for="item in terminalArr" :value="item.value" :key="item.value" :label="item.label"></el-option>
										</el-select>
									</el-col>
								</el-row>
							</el-col>
						</el-row>
						<el-row :gutter="10" class='currentRow1'>
							<el-col :offset='1' :span="11">
								<el-row>
									<el-col :span="8">
										<span class="font14 marginTop5">文件大小：</span>
									</el-col>
									<el-col :span="16">
										<el-input size="mini" placeholder="情输入文件范围" v-model="startKb" clearable @change="inputChange"></el-input>
									</el-col>
								</el-row>
							</el-col>

							<el-col :offset='1' :span="11">
								<el-row>
									<el-col :span="4">
										<span>~</span>
									</el-col>
									<el-col :span="20">
										<el-input size="mini" v-model="endKb" placeholder="情输入文件范围" clearable :disabled="endDisabled"></el-input>
									</el-col>
								</el-row>
							</el-col>
						</el-row>
						<div class="btnBox">
							<el-button type="primary" size="mini" @click="find">确定</el-button>
							<el-button size="mini" @click="closeVis">关闭</el-button>
						</div>
					</el-popover>
				</div>
				<el-button :type="btnType" class='btnMargin' @click='showVis = true' size="mini">更多查询条件</el-button>
			</el-col>
			<el-button type="primary" icon="el-icon-search" size="mini" class='fl' @click='find'>搜索</el-button>
			<el-button icon="el-icon-delete" @click='reset' class='fl' size="mini">重置</el-button>
		</el-row>
		<!-- 	<div class="listName">
			<i></i><span class="font14">电梯大修列表</span>
		</div> -->
		<el-row :gutter="10">
			<el-col :span="1.5">
				<el-button type="primary" :disabled="disableBtn" @click='newAdd(2)' size="mini">编辑</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button type="success" :disabled="disableBtn" @click='newAdd(3)' size="mini">详情</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button type="danger" :disabled="disableBtn" @click='remove(1)' size="mini">删除</el-button>
			</el-col>
			<!-- <el-col :span="1.5">
				<el-button type="danger" :disabled="disableBtnAll   " @click='remove(2)' v-if="deleteBtnShow" size="mini">批量删除</el-button>
			</el-col> -->
			<div class="fr">
				<el-button type="success" @click='newAdd(1)' size="mini">新建</el-button>
			</div>
		</el-row>
		<div class="tableBox">
			<vueScroll>
				<el-table :data="tableData" highlight-current-row ref="moviesTable" @row-click="rowClick" @select-all="selectChange"
				 @selection-change="selectChange" style="width: 100%" border header-row-class-name='tableHeader'>
					<el-table-column type="index" class="over" fixed>
					</el-table-column>
					<el-table-column type="selection" min-width="50" fixed>
					</el-table-column>
					<el-table-column label="资源名称" max-width="140">
						<template slot-scope="scope">
							<el-tooltip class="item" effect="dark" :content="scope.row.name" placement="top">
								<span class="speSpan">{{scope.row.name}}</span>
							</el-tooltip>
						</template>
					</el-table-column>
					<el-table-column label="资源类型" max-width="140">
						<template slot-scope="scope">
							<el-tooltip class="item" effect="dark" :content="scope.row.rtypeName" placement="top">
								<span class="speSpan">{{scope.row.rtypeName}}</span>
							</el-tooltip>
						</template>
					</el-table-column>
					<el-table-column label="播放模式" max-width="140">
						<template slot-scope="scope">
							<el-tooltip class="item" effect="dark" :content="scope.row.play_modeName" placement="top">
								<span class="speSpan">{{scope.row.play_modeName}}</span>
							</el-tooltip>
						</template>
					</el-table-column>
					<el-table-column label="适用终端" max-width="120">
						<template slot-scope="scope">
							<el-tooltip class="item" effect="dark" :content="scope.row.ttypeName" placement="top">
								<span class="speSpan">{{scope.row.ttypeName}}</span>
							</el-tooltip>
						</template>
					</el-table-column>
					<el-table-column label="文件大小" max-width="140">
						<template slot-scope="scope">
							<el-tooltip class="item" effect="dark" :content="typeof scope.row.file_size == 'number' ? scope.row.file_size.toString() :scope.row.file_size " placement="top">
								<span class="speSpan">{{scope.row.file_size}}</span>
							</el-tooltip>
						</template>
					</el-table-column>
				</el-table>
				<!-- 分页器 -->
				<div class="pag">
					<el-pagination :current-page="page" :page-sizes="[10, 20, 30, 40]" :page-size="page_size" layout="total, sizes, prev, pager, next, jumper"
					 :total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange">
					</el-pagination>
				</div>
			</vueScroll>
		</div>
		<dialogCom v-if='dialogShow' :rowId='rowId' :dialogVisible='dialogShow' :title='title'  @closeMask='closeMask'
		 @submitDialog='submitDialog'></dialogCom>
	</div>
</template>

<script>
	import dialogCom from "./add.vue"
	import {
		loadFn,
		axiosPost,
		axiosGet,
		axiosDelete,
		axiosPut,
		moment
	} from "@/common.js";
	export default {
		activated() {},
		mounted() {
			this.getTableList()
		},
		components: {
			dialogCom,
		},
		data() {
			return {
				btnType: 'primary',
				showVis: false,
				showProp: true,
				marketingCode: '',
				tableData: [],
				page: 1,
				page_size: 10,
				total: 0,
				loading: true,
				query: '',
				dialogShow: false,
				title: '',
				disableBtn: true,
				checkBoxArr: [],
				rowId: 0,
				addBtnShow: false,
				complieBtnShow: false,
				deleteBtnShow: false,
				readDataShow: false,
				disableBtnAll: true,
				resource: '',
				resourceArr: [{
					label: '图片',
					value: 0
				}, {
					label: '视频',
					value: 1
				}],
				playMode: '',
				playModeArr: [{
					label: '纯视频',
					value: 0
				}, {
					label: '1/2视频',
					value: 1
				}, {
					label: '1/3视频',
					value: 2
				}, {
					label: '纯图片',
					value: 3
				}, {
					label: '1/2图片',
					value: 4
				}, {
					label: '1/3图片',
					value: 5
				}],
				terminal: '',
				terminalArr: [{
					label: '单屏',
					value: 0
				}, {
					label: '双屏',
					value: 1
				}],
				startKb: '',
				endKb: '',
				endDisabled: true
			}
		},
		methods: {
			inputChange(val) {
				if (val) {
					this.endDisabled = false
				} else {
					this.endDisabled = true
					this.endKb = ''
				}
			},
			closeVis() {
				this.showVis = false
				if (this.playMode || this.terminal || this.startKb) {
					this.btnType = 'warning'
				} else {
					this.btnType = 'primary'
				}
			},
			pubLickSearch() {
				if (this.playMode || this.terminal || this.startKb) {
					this.btnType = 'warning'
					this.showVis = true
				} else {
					this.btnType = 'primary'
					this.showVis = false
				}
			},
			remove(val) {
				this.$confirm('此操作将永久删除该资源, 是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					let url = ''
					let data = {

					}
					let arr = this.checkBoxArr.map((item) => {
						return item.id
					})
					console.log(arr)
					if (val == 1) {
						url = '/res/resource/' + this.rowId+'/'

					} else {
						url = '/res/resource/'
						data = {
							ids: arr
						}
					}
					axiosDelete(url, data, (res) => {
						if (res.code == 0) {
							this.$message.success('删除成功')
							this.getTableList()
						} else {
							this.$message.error(res.detail.result)
						}
					})
				}).catch(() => {

				});
			},
			//新建资源
			newAdd(value) {
				this.dialogShow = true
				console.log(this.dialogShow)
				if (value == 1) {
					this.title = '新建资源管理'
					this.rowId = 0
				} else if (value == 2) {
					this.title = '编辑资源管理'
				} else {
					this.title = '资源管理详情'
				}
			},
			submitDialog() {
				this.dialogShow = false
				this.getTableList()
			},
			//关闭添加弹窗
			closeMask(value) {
				this.dialogShow = false
				if (value == 2) {
					this.getTableList()
				}
			},
			//获取表格数据
			getTableList() {
				this.pubLickSearch()
				this.showVis = false
				this.loading = true
				let params = {
					page: this.page,
					page_size_count: this.page_size,
					key_words:this.query,
					rtype:this.resource,
					play_mode:this.playMode,
					ttype:this.terminal,
					file_min:this.startKb,
					file_max:this.endKb
				}
				axiosGet('/res/resource/', params, (res) => {
					this.loading = false
					if (res.code == 0) {
						this.total = res.detail.count
						this.tableData = res.detail.results
						this.tableData.map((item)=>{
							if(item.rtype == '0'){
								item.rtypeName = '图片'
							}else{
								item.rtypeName = '视频'
							}
							if(item.play_mode == '0'){
								item.play_modeName = '纯视频'
							}else if(item.play_mode == '1'){
								item.play_modeName = '1/2视频'
							}else if(item.play_mode == '2'){
								item.play_modeName = '1/3视频'
							}else if(item.play_mode == '3'){
								item.play_modeName = '纯图片'
							}else if(item.play_mode == '4'){
								item.play_modeName = '1/2图片'
							}else if(item.play_mode == '5'){
								item.play_modeName = ' 1/3图片'
							}
							if(item.ttype == '0'){
								item.ttypeName = '单屏'
							}else {
								item.ttypeName = '双屏'
							}
						})
					} else {
						this.$message.error(res.detail.result)
					}
				})
			},
			find() {
				this.page = 1
				this.page_size = 10
				this.getTableList()
			},
			reset() {
				this.startKb = ''
				this.endKb = ''
				this.terminal = ''
				this.playMode = ''
				this.showVis = false
				this.resource = ''
				this.page = 1
				this.page_size = 10
				this.query = ''
				this.getTableList()
			},
			//表格
			rowClick(row, column, event) {
				this.$refs.moviesTable.toggleRowSelection(row)
			},
			selectChange(res) {
				console.log(res)
				if (res.length == 1) {
					this.disableBtn = false
					this.rowId = res[0].id
				} else {
					this.disableBtn = true
				}
				if (res.length > 1) {
					this.disableBtnAll = false
				} else {
					this.disableBtnAll = true
				}
				this.checkBoxArr = res
			},
			//分页器
			handleSizeChange(size) {
				this.page_size = size
				this.getTableList()
			},
			handleCurrentChange(page) {
				this.page = page
				this.getTableList()
			},

		},
	}
</script>

<style scoped lang="less">
	.colItem {
		display: flex;
		flex-direction: row;

		.searchCode {
			display: flex;
			flex-direction: row;
			justify-content: center;
			align-items: center;
			width: 120px;
		}
	}

	.tableBox {
		height: 80%;
		overflow-y: auto;
	}

	.listName {
		display: flex;
		justify-content: flex-start;
		text-align: left;
		height: 25px;
		align-items: center;

		i {
			width: 3px;
			height: 60%;
			background: #2d8cf0;
			margin: 10px 5px;
		}

	}

	.marginTop5 {
		display: inline-block;
		margin-top: 5px;
	}
</style>
